<!--  活动列表  -->
<template>
  <div id="table-area">
    <h2>学部岗位内推列表</h2>
    <el-table
      :loading="listLoading"
      :data="list.slice((this.currentPage-1)*pagesize,currentPage*pagesize)"
      element-loading-text="Loading"
      border
      fit
      highlight-current-row
    >
      <el-table-column
        align="center"
        prop="jobId"
        label="岗位编号"
        width="150px"
      />

      <el-table-column
        align="center"
        prop="jobName"
        label="岗位名称"
        width="200px"
      />

      <el-table-column
        align="center"
        prop="jobCompany"
        label="岗位公司"
        width="200px"
      />

      <el-table-column
        align="center"
        prop="jobSalary"
        label="岗位薪资"
        width="200px"
      />

      <el-table-column
        align="center"
        prop="jobAddress"
        label="工作地点"
        width="200px"
      />

      <el-table-column
        align="center"
        prop="jobType"
        label="岗位类型"
        width="200px"
      >
        <template slot-scope="scope">
          <span v-if="scope.row.jobType=='1'">学部可见</span>
          <span v-if="scope.row.jobType=='2'">全部可见</span>
        </template>
      </el-table-column>

      <el-table-column
        align="center"
        prop="jobStatus"
        label="岗位状态"
        width="200px"
      >
        <template slot-scope="scope">
          <span v-if="scope.row.jobStatus=='0'">审核中</span>
          <span v-if="scope.row.jobStatus=='1'">已公布</span>
        </template>
      </el-table-column>

      <el-table-column align="center" label="操作">
        <template slot-scope="Scope">
          <el-button type="primary" icon="el-icon-search" size="mini" @click="getJobInfo(Scope.row.jobId)">详情</el-button>
          <el-button type="warning" icon="el-icon-edit" size="mini" @click="updateJobStatus(Scope.row.jobId)">变更</el-button>
          <el-button type="warning" icon="el-icon-edit" size="mini" @click="deleteJob(Scope.row.jobId)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div id="pages">
      <el-pagination
        :current-page="currentPage"
        :page-sizes="[10]"
        :page-size="pagesize"
        layout="total, sizes,prev, pager, next"
        :total="list.length"
        prev-text="上一页"
        next-text="下一页"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </div>
    <job-info ref="info" :job-id="jobId" :show="show" />
  </div>

</template>

<script>
// 这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
// 例如：import 《组件名称》 from '《组件路径》';
import { getJobByJobPartId, getJobByJobId, updateJobStatus, deleteJob } from '../../api/job.js'
import Info from '../../components/job/info.vue'
export default {
  name: '',
  // import引入的组件需要注入到对象中才能使用
  components: {
    'job-info': Info
  },
  props: {
    jobId: String,
    type: String
  },
  data() {
    return {
      jobId: '',
      jobStatus: '',
      show: false,
      dialogFormVisible: false,
      search: {},
      listLoading: false,
      list: [],
      currentPage: 1, // 默认显示页面为1
      pagesize: 10 //    每页的数据条数
    }
  },
  // 监听属性 类似于data概念
  computed: {},
  // 监控data中的数据变化
  watch: {},
  // 生命周期 - 创建完成（可以访问当前this实例）
  created() {
    this.getJobByJobPartId()
  },
  // 生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {},
  beforeCreate() {}, // 生命周期 - 创建之前
  beforeMount() {}, // 生命周期 - 挂载之前
  beforeUpdate() {}, // 生命周期 - 更新之前
  updated() {}, // 生命周期 - 更新之后
  beforeDestroy() {}, // 生命周期 - 销毁之前
  destroyed() {}, // 生命周期 - 销毁完成
  activated() {},
  // 方法集合
  methods: {
    // 每页下拉显示数据
    handleSizeChange(size) {
      this.pagesize = size
    },
    // 点击第几页
    handleCurrentChange(currentPage) {
      console.log(this)
      this.currentPage = currentPage
    },
    handleClick(row) {
      console.log(row)
    },
    getJobByJobPartId() {
      getJobByJobPartId().then((data) => {
        this.list = data.obj
        this.listLoading = false
      })
    },
    getJobInfo(jobId) {
      this.$refs.info.showInfo(jobId)
    },
    updateJobStatus(jobId) {
      getJobByJobId(jobId).then((data) => {
        this.jobStatus = data.obj.jobStatus
        switch (this.jobStatus) {
          case '0':updateJobStatus(jobId, 1); break
          case '1':updateJobStatus(jobId, 0); break
        }
        this.$message({
          showClose: true,
          message: '变更成功',
          type: 'success'
        })
        location.reload()
      })
    },
    deleteJob(jobId) {
      deleteJob(jobId).then((data) => {
        this.$message({
          showClose: true,
          message: '删除成功',
          type: 'success'
        })
        location.reload()
      })
    }
  } // 如果页面有keep-alive缓存功能，这个函数会触发
}
</script>
<style scoped>
  #table-area{
    margin-left: 10px;
    margin-right: 10px;
  }
</style>
